package shuaige.jdk.多线程.base.线程类方法使用示例;

public class 将线程放入数组 implements Runnable {

    public static void main(String[] args) {
        示例方法();
    }


    public static void 示例方法() {
        Thread t = Thread.currentThread();
        t.setName("Admin Thread");

        // 设置线程的优先级
        t.setPriority(1);

        // 打印当前的线程
        System.out.println("Thread = " + t);

        // 返回当前线程的线程组及其子组中活动线程数的估计值。 递归迭代当前线程的线程组中的所有子组。
        int count = Thread.activeCount();
        System.out.println("currently active threads = " + count);

        Thread[] th = new Thread[count];
        // 返回放入数组的线程数
        Thread.enumerate(th);

        // prints active threads
        for (int i = 0; i < count; i++) {
            System.out.println(i + ": " + th[i].getName());
        }

    }

    @Override
    public void run() {
        Thread thread = Thread.currentThread();
        System.out.println("This is run() method-" + thread.getName());
    }

}